package com.zhixinhuixue.zsyte.xxx.ui.activity

import android.content.Context
import android.os.Bundle
import android.util.DisplayMetrics
import android.util.Log
import android.view.WindowManager
import com.zhixinhuixue.zsyte.xxx.R
import com.zhixinhuixue.zsyte.xxx.app.base.BaseNewActivity
import com.zhixinhuixue.zsyte.xxx.app.util.GetScreenParam
import com.zhixinhuixue.zsyte.xxx.databinding.ActivityMainBinding
import com.zhixinhuixue.zsyte.xxx.ui.adapter.MainAdapter
import com.zhixinhuixue.zsyte.xxx.ui.viewmodel.TestViewModel

/**
 * 作者　: hegaojian
 * 时间　: 2020/11/6
 * 描述　:
 */
class MainActivity : BaseNewActivity<TestViewModel, ActivityMainBinding>() {
    private fun getScreenParam(context: Context) {
        val wm = context.getSystemService(WINDOW_SERVICE) as WindowManager
        val dm = DisplayMetrics()
        wm.defaultDisplay.getMetrics(dm)
        val width = dm.widthPixels // 屏幕宽度（像素）
        val height = dm.heightPixels // 屏幕高度（像素）
        val density = dm.density // 屏幕密度（0.75 / 1.0 / 1.5）
        val densityDpi = dm.densityDpi // 屏幕密度dpi（120 / 160 / 240）
        // 屏幕宽度算法:屏幕宽度（像素）/屏幕密度
        val screenWidth = (width / density).toInt() // 屏幕宽度(dp)
        val screenHeight = (height / density).toInt() // 屏幕高度(dp)
        Log.d("ScreenParam", "屏幕宽度（像素）：$width")
        Log.d("ScreenParam", "屏幕高度（像素）：$height")
        Log.d("ScreenParam", "屏幕密度（0.75 / 1.0 / 1.5）：$density")
        Log.d("ScreenParam", "屏幕密度dpi（120 / 160 / 240）：$densityDpi")
        Log.d("ScreenParam", "屏幕宽度（dp）：$screenWidth")
        Log.d("ScreenParam", "屏幕高度（dp）：$screenHeight")
    }

    override fun initView(savedInstanceState: Bundle?) {
        getScreenParam(this)
        mToolbar.setCenterTitle(R.string.bottom_title_read)
        mViewBinding.mainViewPager.adapter = MainAdapter(this)
        mViewBinding.mainViewPager.offscreenPageLimit = mViewBinding.mainViewPager.adapter!!.itemCount
        mViewBinding.mainViewPager.isUserInputEnabled = false
        mViewBinding.mainNavigation.setOnNavigationItemSelectedListener { item ->
            when (item.itemId) {
                R.id.navigationRead -> {
                    mViewBinding.mainViewPager.setCurrentItem(0, false)
                }
                R.id.navigationPaper -> {
                    mViewBinding.mainViewPager.setCurrentItem(1, false)
                }
                R.id.navigationReport -> {
                    mViewBinding.mainViewPager.setCurrentItem(2, false)
                }
                R.id.navigationUser -> {
                    mViewBinding.mainViewPager.setCurrentItem(3, false)
                }
            }
            true
        }
    }

    override fun showToolBar() = false

}
